import { getStore, setStore } from '@/util/store'
export default {
    namespaced: true,
    state: {
        manufacturer:null,
        patient:new Map(),
        dataMap:new Map(),
        globalOrg:{
            id:-1
        },
        globalAlarmType:[],
        globalMenuIndex: getStore({ name: 'gloablMenuIndex' })||0
    },
    actions: {
        setData({commit},data){
            commit('SET_DATA',data)
        },
        setMap({commit},data){
            commit('SET_MAP',data)
        },
        setPatient({commit},data){
            commit('SET_PATIENT',data)
        },
        setGlobalOrg({commit},data){
            commit('SET_ORG',data)
        },
        setGlobalMenuIndex({commit},data){
            commit('SET_MENU_INDEX',data)
        },
        setAlarmType({commit},data){
            commit('SET_ALARMTYPE',data)
        },
    },
    mutations: {
        SET_DATA:(state,obj)=>{
            for(let key in obj){
                state[key] = obj[key]||null
            }
        },
        SET_MAP:(state,{key,value})=>{
            state.dataMap.set(key,value)
        },
        SET_PATIENT:(state,{key,value})=>{
            state.patient.set(key,value)
        },
        SET_ORG:(state,value)=>{
            console.log(value)
            state.globalOrg = value
        },
        SET_ALARMTYPE:(state,value)=>{
            console.log(value)
            state.globalAlarmType = value
        },
        SET_MENU_INDEX:(state,value)=>{
            state.globalMenuIndex = value
            setStore({ name: 'gloablMenuIndex', content: value, type: 'session' })
        },
    }
}
  